package com.tencent.stat;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import com.tencent.mid.api.MidService;
import com.tencent.stat.common.DeviceInfo;
import com.tencent.stat.common.StatCommonHelper;
import com.tencent.stat.common.StatLogger;
import com.tencent.stat.common.StatPreferences;
import com.tencent.stat.common.Util;
import java.net.URI;
import java.util.Iterator;
import org.json.JSONObject;

public class StatConfig
{
  private static int A;
  private static String B;
  private static String C;
  private static String D;
  private static String E;
  private static int F;
  private static String G;
  private static int H;
  private static long I;
  private static long J;
  private static volatile String K;
  private static int L;
  private static volatile int M;
  private static int N;
  private static int O;
  private static boolean P;
  private static int Q;
  private static boolean R;
  private static String S;
  private static boolean T;
  private static StatCustomLogger U;
  private static StatExceptionCallBack V;
  static e a;
  static e b;
  static String c;
  static String d;
  static String e;
  static String f;
  static boolean g;
  static int h;
  static long i;
  public static boolean isAutoExceptionCaught;
  static boolean j;
  static volatile String k;
  static boolean l;
  static int m;
  static long n;
  static int o;
  static StatDataTransfer p;
  private static StatLogger q = StatCommonHelper.getLogger();
  private static StatReportStrategy r;
  private static boolean s;
  private static boolean t;
  private static int u;
  private static int v;
  private static int w;
  private static int x;
  private static int y;
  private static int z;

  static
  {
    a = new e(2);
    b = new e(1);
    r = StatReportStrategy.APP_LAUNCH;
    s = false;
    t = true;
    u = 30000;
    v = 100000;
    w = 30;
    x = 10;
    y = 100;
    z = 30;
    A = 1;
    c = "__HIBERNATE__";
    d = "__HIBERNATE__TIME";
    e = "__MTA_KILL__";
    B = null;
    E = "mta_channel";
    f = "";
    F = 180;
    g = false;
    h = 100;
    i = 10000L;
    H = 1024;
    j = true;
    I = 0L;
    J = 300000L;
    isAutoExceptionCaught = true;
    k = "pingma.qq.com:80";
    K = "http://pingma.qq.com:80/mstat/report";
    L = 0;
    M = 0;
    N = 20;
    O = 0;
    P = false;
    Q = 4096;
    R = false;
    S = null;
    T = false;
    U = null;
    l = true;
    m = 0;
    n = 10000L;
    o = 512;
    p = null;
    V = null;
  }

  static int a()
  {
    return w;
  }

  static String a(Context paramContext)
  {
    return Util.decode(StatPreferences.getString(paramContext, "_mta_ky_tag_", null));
  }

  static String a(String paramString1, String paramString2)
  {
    try
    {
      String str = b.b.getString(paramString1);
      if (str != null)
        paramString2 = str;
      return paramString2;
    }
    catch (Throwable localThrowable)
    {
      q.d("can't find custom key:" + paramString1);
    }
    return paramString2;
  }

  static void a(int paramInt)
  {
    monitorenter;
    try
    {
      M = paramInt;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  static void a(long paramLong)
  {
    StatPreferences.putLong(f.a(), c, paramLong);
    setEnableStatService(false);
    q.warn("MTA is disable for current SDK version");
  }

  static void a(Context paramContext, e parame)
  {
    if (parame.a == b.a)
    {
      b = parame;
      a(parame.b);
      if (!(b.b.isNull("iplist")))
        NetworkManager.getInstance(paramContext).updateIpList(b.b.getString("iplist"));
    }
    do
      return;
    while (parame.a != a.a);
    a = parame;
  }

  static void a(Context paramContext, e parame, JSONObject paramJSONObject)
  {
    int i1 = 0;
    while (true)
    {
      String str;
      try
      {
        Iterator localIterator = paramJSONObject.keys();
        do
        {
          while (true)
          {
            if (!(localIterator.hasNext()))
              break label156;
            str = (String)localIterator.next();
            if (!(str.equalsIgnoreCase("v")))
              break;
            int i2 = paramJSONObject.getInt(str);
            if (parame.d == i2)
              break label210;
            i1 = 1;
            parame.d = i2;
          }
          if (!(str.equalsIgnoreCase("c")))
            break label122;
          str = paramJSONObject.getString("c");
        }
        while (str.length() <= 0);
        label122: parame.b = new JSONObject(str);
      }
      catch (org.json.JSONException paramContext)
      {
        do
        {
          q.e(paramContext);
          return;
        }
        while (!(str.equalsIgnoreCase("m")));
        parame.c = paramJSONObject.getString("m");
      }
      catch (Throwable paramContext)
      {
        q.e(paramContext);
        return;
      }
      if (i1 == 1)
      {
        label156: paramJSONObject = aw.a(f.a());
        if (paramJSONObject != null)
          paramJSONObject.a(parame);
        if (parame.a == b.a)
        {
          a(parame.b);
          b(parame.b);
        }
      }
      a(paramContext, parame);
      label210: return;
    }
  }

  static void a(Context paramContext, String paramString)
  {
    if (paramString == null)
      return;
    StatPreferences.putString(paramContext, "_mta_ky_tag_", Util.encode(paramString));
  }

  static void a(Context paramContext, JSONObject paramJSONObject)
  {
    while (true)
    {
      try
      {
        Iterator localIterator = paramJSONObject.keys();
        if (!(localIterator.hasNext()))
          break label65;
        localObject = (String)localIterator.next();
        if (!(((String)localObject).equalsIgnoreCase(Integer.toString(b.a))))
          break label66;
        localObject = paramJSONObject.getJSONObject((String)localObject);
        label65: a(paramContext, b, (JSONObject)localObject);
      }
      catch (org.json.JSONException paramContext)
      {
        q.e(paramContext);
        return;
      }
      if (((String)localObject).equalsIgnoreCase(Integer.toString(a.a)))
      {
        label66: localObject = paramJSONObject.getJSONObject((String)localObject);
        a(paramContext, a, (JSONObject)localObject);
      }
      if (!(((String)localObject).equalsIgnoreCase("rs")))
        continue;
      Object localObject = StatReportStrategy.getStatReportStrategy(paramJSONObject.getInt((String)localObject));
      if (localObject == null)
        continue;
      r = (StatReportStrategy)localObject;
      if (!(isDebugEnable()))
        continue;
      q.d("Change to ReportStrategy:" + ((StatReportStrategy)localObject).name());
    }
  }

  static void a(JSONObject paramJSONObject)
  {
    try
    {
      paramJSONObject = StatReportStrategy.getStatReportStrategy(paramJSONObject.getInt("rs"));
      if (paramJSONObject != null)
        setStatSendStrategy(paramJSONObject);
      return;
    }
    catch (org.json.JSONException paramJSONObject)
    {
      if (isDebugEnable());
      q.i("rs not found.");
    }
  }

  static boolean a(int paramInt1, int paramInt2, int paramInt3)
  {
    return ((paramInt1 < paramInt2) || (paramInt1 > paramInt3));
  }

  private static boolean a(String paramString)
  {
    if (paramString == null);
    do
    {
      return false;
      if (C != null)
        continue;
      C = paramString;
      return true;
    }
    while (C.contains(paramString));
    C = C + "|" + paramString;
    return true;
  }

  static boolean a(JSONObject paramJSONObject, String paramString1, String paramString2)
  {
    if (paramJSONObject.isNull(paramString1))
      break label38;
    paramJSONObject = paramJSONObject.optString(paramString1);
    label38: return ((!(StatCommonHelper.isStringValid(paramString2))) || (!(StatCommonHelper.isStringValid(paramJSONObject))) || (!(paramString2.equalsIgnoreCase(paramJSONObject))));
  }

  static void b()
  {
    O += 1;
  }

  static void b(int paramInt)
  {
    if (paramInt < 0)
      return;
    O = paramInt;
  }

  static void b(Context paramContext, JSONObject paramJSONObject)
  {
    while (true)
    {
      Object localObject;
      try
      {
        paramJSONObject = paramJSONObject.optString(e);
        if (!(StatCommonHelper.isStringValid(paramJSONObject)))
          return;
        paramJSONObject = new JSONObject(paramJSONObject);
        if (paramJSONObject.length() == 0)
          return;
        if (!(paramJSONObject.isNull("sm")))
        {
          localObject = paramJSONObject.get("sm");
          if (!(localObject instanceof Integer))
            break label532;
          i1 = ((Integer)localObject).intValue();
          if (i1 > 0)
          {
            if (isDebugEnable())
              q.i("match sleepTime:" + i1 + " minutes");
            long l1 = System.currentTimeMillis();
            long l2 = i1 * 60 * 1000;
            StatPreferences.putLong(paramContext, d, l1 + l2);
            setEnableStatService(false);
            q.warn("MTA is disable for current SDK version");
          }
        }
        if (!(a(paramJSONObject, "sv", "2.0.4")))
          break label555;
        q.i("match sdk version:2.0.4");
        i1 = 1;
        if (a(paramJSONObject, "md", Build.MODEL))
        {
          q.i("match MODEL:" + Build.MODEL);
          i1 = 1;
        }
        if (a(paramJSONObject, "av", StatCommonHelper.getCurAppVersion(paramContext)))
        {
          q.i("match app version:" + StatCommonHelper.getCurAppVersion(paramContext));
          i1 = 1;
        }
        if (a(paramJSONObject, "mf", Build.MANUFACTURER))
        {
          q.i("match MANUFACTURER:" + Build.MANUFACTURER);
          i1 = 1;
        }
        if (a(paramJSONObject, "osv", Build.VERSION.SDK_INT))
        {
          q.i("match android SDK version:" + Build.VERSION.SDK_INT);
          i1 = 1;
        }
        if (a(paramJSONObject, "ov", Build.VERSION.SDK_INT))
        {
          q.i("match android SDK version:" + Build.VERSION.SDK_INT);
          i1 = 1;
        }
        if (a(paramJSONObject, "ui", aw.a(paramContext).b(paramContext).getImei()))
        {
          q.i("match imei:" + aw.a(paramContext).b(paramContext).getImei());
          i1 = 1;
        }
        if (a(paramJSONObject, "mid", getLocalMidOnly(paramContext)))
        {
          q.i("match mid:" + getLocalMidOnly(paramContext));
          i1 = 1;
        }
        if (i1 == 0)
          return;
        a(StatCommonHelper.getSDKLongVersion("2.0.4"));
        return;
      }
      catch (java.lang.Exception paramContext)
      {
        q.e(paramContext);
        return;
      }
      if (localObject instanceof String)
      {
        label532: i1 = Integer.valueOf((String)localObject).intValue();
        continue;
        label555: i1 = 0;
      }
      int i1 = 0;
    }
  }

  static void b(JSONObject paramJSONObject)
  {
    if ((paramJSONObject == null) || (paramJSONObject.length() == 0))
      return;
    try
    {
      long l1;
      do
      {
        b(f.a(), paramJSONObject);
        paramJSONObject = paramJSONObject.getString(c);
        if (isDebugEnable())
          q.d("hibernateVer:" + paramJSONObject + ", current version:2.0.4");
        l1 = StatCommonHelper.getSDKLongVersion(paramJSONObject);
      }
      while (StatCommonHelper.getSDKLongVersion("2.0.4") > l1);
      a(l1);
      return;
    }
    catch (org.json.JSONException paramJSONObject)
    {
      q.d("__HIBERNATE__ not found.");
    }
  }

  static int c()
  {
    return O;
  }

  protected static StatExceptionCallBack d()
  {
    return V;
  }

  public static String getAppKey(Context paramContext)
  {
    monitorenter;
    while (true)
      try
      {
        if (C != null)
        {
          paramContext = C;
          return paramContext;
        }
        if ((paramContext != null) && (C == null))
          C = StatCommonHelper.getAppKey(paramContext);
        if ((C == null) || (C.trim().length() == 0))
          q.e("AppKey can not be null or empty, please read Developer's Guide first!");
      }
      finally
      {
        monitorexit;
      }
  }

  public static int getCurSessionStatReportCount()
  {
    return M;
  }

  public static StatCustomLogger getCustomLogger()
  {
    return U;
  }

  public static String getCustomProperty(String paramString)
  {
    try
    {
      paramString = a.b.getString(paramString);
      return paramString;
    }
    catch (Throwable paramString)
    {
      q.e(paramString);
    }
    return null;
  }

  public static String getCustomProperty(String paramString1, String paramString2)
  {
    try
    {
      paramString1 = a.b.getString(paramString1);
      if (paramString1 != null)
        paramString2 = paramString1;
      return paramString2;
    }
    catch (Throwable paramString1)
    {
      q.e(paramString1);
    }
    return paramString2;
  }

  public static String getCustomUserId(Context paramContext)
  {
    if (paramContext == null)
    {
      q.error("Context for getCustomUid is null.");
      return null;
    }
    if (S == null);
    try
    {
      S = StatPreferences.getString(paramContext, "MTA_CUSTOM_UID", "");
      return S;
    }
    catch (java.lang.ClassCastException paramContext)
    {
      q.e(paramContext);
    }
  }

  public static StatDataTransfer getDataTransfer()
  {
    return p;
  }

  public static long getFlushDBSpaceMS()
  {
    return n;
  }

  public static String getInstallChannel(Context paramContext)
  {
    monitorenter;
    while (true)
      try
      {
        if (D != null)
        {
          paramContext = D;
          return paramContext;
        }
        String str = StatPreferences.getString(paramContext, E, "");
        D = str;
        if ((str == null) || (D.trim().length() == 0))
          D = StatCommonHelper.getInstallChannel(paramContext);
        if ((D == null) || (D.trim().length() == 0))
          q.w("installChannel can not be null or empty, please read Developer's Guide first!");
      }
      finally
      {
        monitorexit;
      }
  }

  public static String getLocalMidOnly(Context paramContext)
  {
    return MidService.getLocalMidOnly(paramContext);
  }

  public static String getMTAPreferencesFileName()
  {
    return G;
  }

  public static int getMaxBatchReportCount()
  {
    return z;
  }

  public static int getMaxDaySessionNumbers()
  {
    return N;
  }

  public static int getMaxImportantDataSendRetryCount()
  {
    return y;
  }

  public static int getMaxParallelTimmingEvents()
  {
    return H;
  }

  public static int getMaxReportEventLength()
  {
    return Q;
  }

  public static int getMaxSendRetryCount()
  {
    return x;
  }

  public static int getMaxSessionStatReportCount()
  {
    return L;
  }

  public static int getMaxStoreEventCount()
  {
    return v;
  }

  public static String getMid(Context paramContext)
  {
    return MidService.getMid(paramContext);
  }

  public static long getMsPeriodForMethodsCalledLimitClear()
  {
    return i;
  }

  public static int getNumEventsCachedInMemory()
  {
    return m;
  }

  public static int getNumEventsCommitPerSec()
  {
    return A;
  }

  public static int getNumOfMethodsCalledLimit()
  {
    return h;
  }

  public static String getQQ(Context paramContext)
  {
    return StatPreferences.getString(paramContext, "mta.acc.qq", f);
  }

  public static int getReportCompressedSize()
  {
    return o;
  }

  public static int getSendPeriodMinutes()
  {
    return F;
  }

  public static int getSessionTimoutMillis()
  {
    return u;
  }

  public static String getStatReportHost()
  {
    return k;
  }

  public static String getStatReportUrl()
  {
    return K;
  }

  public static StatReportStrategy getStatSendStrategy()
  {
    return r;
  }

  public static void initNativeCrashReport(Context paramContext, String paramString)
  {
    if (!(isEnableStatService()))
      return;
    if (paramContext == null)
    {
      q.error("The Context of StatConfig.initNativeCrashReport() can not be null!");
      return;
    }
    StatNativeCrashReport.initNativeCrash(paramContext, paramString);
  }

  public static boolean isAutoExceptionCaught()
  {
    return isAutoExceptionCaught;
  }

  public static boolean isDebugEnable()
  {
    return s;
  }

  public static boolean isEnableConcurrentProcess()
  {
    return R;
  }

  public static boolean isEnableSmartReporting()
  {
    return j;
  }

  public static boolean isEnableStatService()
  {
    return t;
  }

  public static boolean isReportEventsByOrder()
  {
    return l;
  }

  public static boolean isXGProMode()
  {
    return T;
  }

  public static void setAppKey(Context paramContext, String paramString)
  {
    if (paramContext == null)
      q.error("ctx in StatConfig.setAppKey() is null");
    do
    {
      return;
      if ((paramString == null) || (paramString.length() > 256))
      {
        q.error("appkey in StatConfig.setAppKey() is null or exceed 256 bytes");
        return;
      }
      if (C != null)
        continue;
      C = a(paramContext);
    }
    while (!((a(paramString) | a(StatCommonHelper.getAppKey(paramContext)))));
    a(paramContext, C);
  }

  public static void setAppKey(String paramString)
  {
    if (paramString == null)
    {
      q.error("appkey in StatConfig.setAppKey() is null");
      return;
    }
    if (paramString.length() > 256)
    {
      q.error("The length of appkey cann't exceed 256 bytes.");
      return;
    }
    C = paramString;
  }

  public static void setAutoExceptionCaught(boolean paramBoolean)
  {
    isAutoExceptionCaught = paramBoolean;
  }

  public static void setCustomLogger(StatCustomLogger paramStatCustomLogger)
  {
    U = paramStatCustomLogger;
  }

  public static void setCustomUserId(Context paramContext, String paramString)
  {
    if (paramContext == null)
    {
      q.error("Context for setCustomUid is null.");
      return;
    }
    StatPreferences.putString(paramContext, "MTA_CUSTOM_UID", paramString);
    S = paramString;
  }

  public static void setDataTransfer(StatDataTransfer paramStatDataTransfer)
  {
    p = paramStatDataTransfer;
  }

  public static void setDebugEnable(boolean paramBoolean)
  {
    s = paramBoolean;
    StatCommonHelper.getLogger().setDebugEnable(paramBoolean);
  }

  public static void setEnableConcurrentProcess(boolean paramBoolean)
  {
    R = paramBoolean;
  }

  public static void setEnableSmartReporting(boolean paramBoolean)
  {
    j = paramBoolean;
  }

  public static void setEnableStatService(boolean paramBoolean)
  {
    t = paramBoolean;
    if (paramBoolean)
      return;
    q.warn("!!!!!!MTA StatService has been disabled!!!!!!");
  }

  public static void setFlushDBSpaceMS(long paramLong)
  {
    if (paramLong <= 0L)
      return;
    n = paramLong;
  }

  public static void setInstallChannel(Context paramContext, String paramString)
  {
    if (paramString.length() > 128)
    {
      q.error("the length of installChannel can not exceed the range of 128 bytes.");
      return;
    }
    D = paramString;
    StatPreferences.putString(paramContext, E, paramString);
  }

  public static void setInstallChannel(String paramString)
  {
    if (paramString.length() > 128)
    {
      q.error("the length of installChannel can not exceed the range of 128 bytes.");
      return;
    }
    D = paramString;
  }

  public static void setMTAPreferencesFileName(String paramString)
  {
    G = paramString;
  }

  public static void setMaxBatchReportCount(int paramInt)
  {
    if (!(a(paramInt, 2, 1000)))
    {
      q.error("setMaxBatchReportCount can not exceed the range of [2,1000].");
      return;
    }
    z = paramInt;
  }

  public static void setMaxDaySessionNumbers(int paramInt)
  {
    if (paramInt <= 0)
    {
      q.e("maxDaySessionNumbers must be greater than 0.");
      return;
    }
    N = paramInt;
  }

  public static void setMaxImportantDataSendRetryCount(int paramInt)
  {
    if (paramInt <= 100)
      return;
    y = paramInt;
  }

  public static void setMaxParallelTimmingEvents(int paramInt)
  {
    if (!(a(paramInt, 1, 4096)))
    {
      q.error("setMaxParallelTimmingEvents can not exceed the range of [1, 4096].");
      return;
    }
    H = paramInt;
  }

  public static void setMaxReportEventLength(int paramInt)
  {
    if (paramInt <= 0)
    {
      q.error("maxReportEventLength on setMaxReportEventLength() must greater than 0.");
      return;
    }
    Q = paramInt;
  }

  public static void setMaxSendRetryCount(int paramInt)
  {
    if (!(a(paramInt, 1, 1000)))
    {
      q.error("setMaxSendRetryCount can not exceed the range of [1,1000].");
      return;
    }
    x = paramInt;
  }

  public static void setMaxSessionStatReportCount(int paramInt)
  {
    if (paramInt < 0)
    {
      q.error("maxSessionStatReportCount cannot be less than 0.");
      return;
    }
    L = paramInt;
  }

  public static void setMaxStoreEventCount(int paramInt)
  {
    if (!(a(paramInt, 0, 500000)))
    {
      q.error("setMaxStoreEventCount can not exceed the range of [0, 500000].");
      return;
    }
    v = paramInt;
  }

  public static void setNativeCrashDebugEnable(boolean paramBoolean)
  {
    StatNativeCrashReport.setNativeCrashDebugEnable(paramBoolean);
  }

  public static void setNumEventsCachedInMemory(int paramInt)
  {
    if (paramInt < 0)
      return;
    m = paramInt;
  }

  public static void setNumEventsCommitPerSec(int paramInt)
  {
    if (paramInt <= 0)
      return;
    A = paramInt;
  }

  public static void setNumOfMethodsCalledLimit(int paramInt, long paramLong)
  {
    h = paramInt;
    if (paramLong < 1000L)
      return;
    i = paramLong;
  }

  public static void setQQ(Context paramContext, String paramString)
  {
    StatPreferences.putString(paramContext, "mta.acc.qq", paramString);
    f = paramString;
  }

  public static void setReportCompressedSize(int paramInt)
  {
    if (paramInt <= 0)
      return;
    o = paramInt;
  }

  public static void setReportEventsByOrder(boolean paramBoolean)
  {
    l = paramBoolean;
  }

  public static void setSendPeriodMinutes(int paramInt)
  {
    if (!(a(paramInt, 1, 10080)))
    {
      q.error("setSendPeriodMinutes can not exceed the range of [1, 7*24*60] minutes.");
      return;
    }
    F = paramInt;
  }

  public static void setSessionTimoutMillis(int paramInt)
  {
    if (!(a(paramInt, 1000, 86400000)))
    {
      q.error("setSessionTimoutMillis can not exceed the range of [1000, 24 * 60 * 60 * 1000].");
      return;
    }
    u = paramInt;
  }

  public static void setStatExCallBack(StatExceptionCallBack paramStatExceptionCallBack)
  {
    V = paramStatExceptionCallBack;
  }

  public static void setStatReportUrl(String paramString)
  {
    if ((paramString == null) || (paramString.length() == 0))
    {
      q.error("statReportUrl cannot be null or empty.");
      return;
    }
    K = paramString;
    while (true)
      try
      {
        do
          k = new URI(K).getHost();
        while (!(isDebugEnable()));
        q.i("url:" + K + ", domain:" + k);
        return;
      }
      catch (java.lang.Exception paramString)
      {
        q.w(paramString);
      }
  }

  public static void setStatSendStrategy(StatReportStrategy paramStatReportStrategy)
  {
    r = paramStatReportStrategy;
    if (paramStatReportStrategy != StatReportStrategy.PERIOD)
      StatServiceImpl.c = 0L;
    if (!(isDebugEnable()))
      return;
    q.d("Change to statSendStrategy: " + paramStatReportStrategy);
  }

  public static void setXGProMode(boolean paramBoolean)
  {
    T = paramBoolean;
  }
}